package com.baosight.sczx.common.zm.cInterface.cm;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baosight.iplat4j.core.ei.EiBlock;
import com.baosight.iplat4j.core.ei.EiColumn;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.core.spring.SpringApplicationContext;
import com.baosight.iplat4j.dao.Dao;

/**
 * 物资分类
 * <p>Title: MaterialType.java</p>
 * <p>Description: </p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 杨鸣
 * @version 1.0
 * <pre>Histroy:
 *          2011-6-1 下午05:20:13  杨鸣  Create
 *</pre>
 */
public class MaterialTypeReport {
	
	private static Dao dao = (Dao)SpringApplicationContext.getBean("dao");
	
	/**
	 * 得到某个类别下所有可加物资的最小类别
	 * <p>Function: getIsAddTypeInfo</p>
	 * <p>Description: </p>
	 * <p>return value:List<Map></p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-6-17下午04:06:39 杨鸣
	 * </p>
	 *
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public static List<Map> getIsAddTypeInfo(String TreeTypeInnerCode){
		List<Map> _list = new ArrayList<Map>();
		try {
			Map _argMap = new HashMap();
			_argMap.put("fdTypeInnerCode", TreeTypeInnerCode);
			_list = dao.query("ZMCMMaterialType.isAddTypeInfo", _argMap);
		} catch (Exception e) {
			return _list;
		}
		return _list;
	}
	
	/**
	 * 判断某个类别是否有子类别
	 * <p>Function: hasChildrenType</p>
	 * <p>Description: </p>
	 * <p>return value:boolean</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-6-17下午04:43:25 杨鸣
	 * </p>
	 *
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public static boolean hasChildrenType(Map<String,String> _argMap, EiInfo eiInfo) {
		List<Map>  _list = new ArrayList();
		try {
			_list = dao.query("ZMCMMaterialTypeReport.queryHasChildrenType", _argMap);
			if(_list.size() < 1) {
				return false;
			}
			else {
			}
		} catch (Exception e) {
			
		}
		
		return true;
	}	
	
	/**
	 * 判断某个类别是否有数据
	 * <p>Function: hasChildrenData</p>
	 * <p>Description: </p>
	 * <p>return value:boolean</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-6-17下午04:43:25 杨鸣
	 * </p>
	 *
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public static boolean hasChildrenData(EiInfo eiInfo) {
		List<Map>  _list = new ArrayList();
		String fdTypeInnerCode = eiInfo.getString("fdTypeInnerCode");
		Map<String, String> _map = new HashMap<String, String>();
		_map.put("treeTypeInnerCode", fdTypeInnerCode);
		try {
			_list = dao.query("ZMCMMaterialBasicInfoReport.query", _map);
			if(_list.size() < 1) {
				return false;
			}
			else {
			}
		} catch (Exception e) {
			
		}
		
		return true;
	}	
	
	/**
	 * 构造物资分类block
	 * <p>Function: getMateroalName</p>
	 * <p>Description: </p>
	 * <p>return value:EiBlock</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-6-7下午02:48:28 贾雪民
	 * </p>
	 *
	 */
	@SuppressWarnings("rawtypes")
	public static EiBlock getMateroalName(){
	    EiBlock block = new EiBlock("cmes.cm.materoalName");
			
	    EiColumn eiColumn = new EiColumn("fdTypeAllCode");
		eiColumn.setType("C");
		block.addMeta(eiColumn);
		
		eiColumn = new EiColumn("materoalName");
		eiColumn.setType("C");
		block.addMeta(eiColumn);
		Map<String, String> _map = new HashMap<String, String>();
		List<Map> list = Material.getMateroalNames(_map,"ZMCMMaterialType.allType");
		
		block.setRows(list);
		return block;	
	}
}
